﻿// Copyright 2008 William P. Hickey Jr. and William U. Walker
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//     
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//  
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using AgwpePort.Aprs;

namespace CSReporter
{
    public partial class ReportForm : Form
    {
        private bool editExisting;
        private MainForm mainForm;
        private ConfigList configure;
        private StatusTextList statusText;
        private StationList stations;
        private MessageList messages;
        private CSReportList csReports;
        private AutoCompleteStringCollection callSigns;

        #region " Constructor and Load event handler "
        public ReportForm()
        {
            InitializeComponent();
            IncidentTimePicker.ShowUpDown = true;
            editExisting = false;
            mainForm = MainForm.GetMainForm();

            // Get the MesssageList object.
            messages = MessageList.GetMessageList();
            // Get the ConfigList object.
            configure = ConfigList.GetConfigList();
            // Get the StatusTextList object.
            statusText = StatusTextList.GetStatusTextList();
            // Get the StationList object.
            stations = StationList.GetStationList();
            // Instantiate a new CSReportList object using the messages MessageList object.
            csReports = new CSReportList(messages);
        }

        private void ReportForm_Load(object sender, EventArgs e)
        {
            // Set dialog titles and labels.
            FillStatusTitleText();
            // Get the list of call signs from the StationList object.
            var calls =
                from station in stations
                orderby station.CallSign
                select station.CallSign;
            // Intantiate the callSign object.
            callSigns = new AutoCompleteStringCollection();
            // Loop through all station records.
            foreach (string call in calls)
            {
                // Add the station call to the autocomplete list.
                callSigns.Add(call);
            }
            // If any call signs were found...
            if (callSigns[0] != null)
            {
                // Assign the autocomplete list to the StationTextBox.AutoCompleteCustomSource property.
                StationTextBox.AutoCompleteCustomSource = callSigns;
            }
            // If this is a new community status report.
            if(!editExisting)
                // Initialize the input fields.
                ClearReportData();
            // Set focus to the Station textbox.
            StationTextBox.Focus();
        }
        #endregion
        #region " Additional methods and handlers "
        private void FillStatusTitleText()
        {
            // Set the status title text.
            StatusGroupBox1.Text = statusText[0].Status1;
            StatusGroupBox2.Text = statusText[0].Status2;
            StatusGroupBox3.Text = statusText[0].Status3;
            StatusGroupBox4.Text = statusText[0].Status4;
            StatusGroupBox5.Text = statusText[0].Status5;
            StatusGroupBox6.Text = statusText[0].Status6;
            StatusGroupBox7.Text = statusText[0].Status7;
            StatusGroupBox8.Text = statusText[0].Status8;
            StatusGroupBox9.Text = statusText[0].Status9;
            StatusGroupBox10.Text = statusText[0].Status10;
            StatusGroupBox11.Text = statusText[0].Status11;
            StatusGroupBox12.Text = statusText[0].Status12;
            StatusGroupBox13.Text = statusText[0].Status13;
            StatusGroupBox14.Text = statusText[0].Status14;
            StatusGroupBox15.Text = statusText[0].Status15;
            StatusGroupBox16.Text = statusText[0].Status16;
            // Set the status radiobutton text.
            Red1.Text = statusText[0].Status1R;
            Yellow1.Text = statusText[0].Status1Y;
            Green1.Text = statusText[0].Status1G;
            White1.Text = statusText[0].Status1W;
            Red2.Text = statusText[0].Status2R;
            Yellow2.Text = statusText[0].Status2Y;
            Green2.Text = statusText[0].Status2G;
            White2.Text = statusText[0].Status2W;
            Red3.Text = statusText[0].Status3R;
            Yellow3.Text = statusText[0].Status3Y;
            Green3.Text = statusText[0].Status3G;
            White3.Text = statusText[0].Status3W;
            Red4.Text = statusText[0].Status4R;
            Yellow4.Text = statusText[0].Status4Y;
            Green4.Text = statusText[0].Status4G;
            White4.Text = statusText[0].Status4W;
            Red5.Text = statusText[0].Status5R;
            Yellow5.Text = statusText[0].Status5Y;
            Green5.Text = statusText[0].Status5G;
            White5.Text = statusText[0].Status5W;
            Red6.Text = statusText[0].Status6R;
            Yellow6.Text = statusText[0].Status6Y;
            Green6.Text = statusText[0].Status6G;
            White6.Text = statusText[0].Status6W;
            Red7.Text = statusText[0].Status7R;
            Yellow7.Text = statusText[0].Status7Y;
            Green7.Text = statusText[0].Status7G;
            White7.Text = statusText[0].Status7W;
            Red8.Text = statusText[0].Status8R;
            Yellow8.Text = statusText[0].Status8Y;
            Green8.Text = statusText[0].Status8G;
            White8.Text = statusText[0].Status8W;
            Red9.Text = statusText[0].Status9R;
            Yellow9.Text = statusText[0].Status9Y;
            Green9.Text = statusText[0].Status9G;
            White9.Text = statusText[0].Status9W;
            Red10.Text = statusText[0].Status10R;
            Yellow10.Text = statusText[0].Status10Y;
            Green10.Text = statusText[0].Status10G;
            White10.Text = statusText[0].Status10W;
            Red11.Text = statusText[0].Status11R;
            Yellow11.Text = statusText[0].Status11Y;
            Green11.Text = statusText[0].Status11G;
            White11.Text = statusText[0].Status11W;
            Red12.Text = statusText[0].Status12R;
            Yellow12.Text = statusText[0].Status12Y;
            Green12.Text = statusText[0].Status12G;
            White12.Text = statusText[0].Status12W;
            Red13.Text = statusText[0].Status13R;
            Yellow13.Text = statusText[0].Status13Y;
            Green13.Text = statusText[0].Status13G;
            White13.Text = statusText[0].Status13W;
            Red14.Text = statusText[0].Status14R;
            Yellow14.Text = statusText[0].Status14Y;
            Green14.Text = statusText[0].Status14G;
            White14.Text = statusText[0].Status14W;
            Red15.Text = statusText[0].Status15R;
            Yellow15.Text = statusText[0].Status15Y;
            Green15.Text = statusText[0].Status15G;
            White15.Text = statusText[0].Status15W;
            Red16.Text = statusText[0].Status16R;
            Yellow16.Text = statusText[0].Status16Y;
            Green16.Text = statusText[0].Status16G;
            White16.Text = statusText[0].Status16W;
        }

        private void StationTextBox_Leave(object sender, System.EventArgs e)
        {
            // Test to see if there is any text in the station textbox.
            if (StationTextBox.Text.Length > 0 & !editExisting)
            {
                // Query the dataset for rows with the station entered.
                Station selectedStation = stations.GetStation(StationTextBox.Text);
                // If the station is in the tbStation table...
                if (selectedStation != null)
                {
                    LatDegTextBox.Text = selectedStation.Latitude.ToString();
                    LonDegTextBox.Text = selectedStation.Longitude.ToString();
                    //// Ask if this station should be added to the tbStation table.
                    //if (MessageBox.Show("This Station is not currently in the list of known stations.\nWould you like to add this station now?", "Unknown Station", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    //{
                    //    // If the save button was clicked...
                    //    TopMost = false;
                    //    EditStationsDialog esd = new EditStationsDialog();
                    //    esd.AddNewStation(StationTextBox.Text);
                    //    if (esd.ShowDialog() == DialogResult.OK)
                    //    {
                    //        // This line of code loads data into the 'esp_dataCEDataSet.tbStation' table.
                    //        tbStationTableAdapter.Fill(esp_dataCEDataSet.tbStation);
                    //        // Fill the SelectedRows array variable.
                    //        selectedRows = esp_dataCEDataSet.tbStation.Select();
                    //        // Loop through all station records.
                    //        for (int count = 0; count < selectedRows.Length; count++)
                    //            // Add all known station calls to the autocomplete list.
                    //            StationTextBox.AutoCompleteCustomSource.Add(selectedRows[count]["Station"].ToString());
                    //    }
                    //    TopMost = true;
                    //}
                }
            }
            // Set editExisting to false;
            editExisting = false;
        }

        private void ClearReportData()
        {
            StationTextBox.Clear();
            ReportIdNumericUpDown.Value = csReports.GetMaxID(configure[0].CallSign) + 1;
            StreetNumberTextBox.Clear();
            StreetDirComboBox.SelectedIndex = -1;
            StreetNameTextBox.Clear();
            CityTextBox.Clear();
            StateComboBox.SelectedIndex = -1;
            CrossRoad1TextBox.Clear();
            CrossRoad2TextBox.Clear();
            LatDegTextBox.Clear();
            LonDegTextBox.Clear();
            IncidentTimePicker.Value = DateTime.Now;
            DetailRichTextBox.Clear();
            ReportToTextBox.Text = configure[0].ReportToCall;
            White1.Checked = true;
            White2.Checked = true;
            White3.Checked = true;
            White4.Checked = true;
            White5.Checked = true;
            White6.Checked = true;
            White7.Checked = true;
            White8.Checked = true;
            White9.Checked = true;
            White10.Checked = true;
            White11.Checked = true;
            White12.Checked = true;
            White13.Checked = true;
            White14.Checked = true;
            White15.Checked = true;
            White16.Checked = true;
        }

        public void NewReport(double latitude, double longitude, string station)
        {
            ClearReportData();
            editExisting = true;
            if (station != null)
            {
                StationTextBox.Text = station.ToUpper().Trim();
                LatDegTextBox.Text = latitude.ToString();
                LonDegTextBox.Text = longitude.ToString();
                StreetNumberTextBox.Focus();
            }
        }

        public void EditReport(CSReportMessage csReport, bool newReport)
        {
            ClearReportData();
            editExisting = true;
            csReports.AddCSReport(csReport);
            StationTextBox.Text = csReport.Station;// editRow.Cells["Station"].Value.ToString();
            StreetNumberTextBox.Text = csReport.StreetNumber;// editRow.Cells["StreetNumber"].Value.ToString();
            StreetDirComboBox.Text = csReport.StreetDirection;// editRow.Cells["StreetDirection"].Value.ToString();
            StreetNameTextBox.Text = csReport.StreetName;// editRow.Cells["StreetName"].Value.ToString();
            CityTextBox.Text = csReport.CityCode;// editRow.Cells["CityCode"].Value.ToString();
            StateComboBox.Text = csReport.StateCode;// editRow.Cells["StateCode"].Value.ToString();
            CrossRoad1TextBox.Text = csReport.CrossRoad1;// editRow.Cells["CrossRoad1"].Value.ToString();
            CrossRoad2TextBox.Text = csReport.CrossRoad2;// editRow.Cells["CrossRoad2"].Value.ToString();
            LatDegTextBox.Text = AprsCalc.LatLonToDouble(csReport.Latitude).ToString();// editRow.Cells["Latitude"].Value.ToString()).ToString();
            LonDegTextBox.Text = AprsCalc.LatLonToDouble(csReport.Longitude).ToString();// editRow.Cells["Longitude"].Value.ToString()).ToString();
            DetailRichTextBox.Text = csReport.DetailText;// editRow.Cells["DetailText"].Value.ToString();

            if (!newReport)
            {
                ReportIdNumericUpDown.Value = Convert.ToInt32(csReport.ReportID);// editRow.Cells["ReportID"].Value);
                IncidentTimePicker.Value = AprsCalc.TimeStampToDateTime(csReport.IncidentTime);// (DateTime)editRow.Cells["IncidentTime"].Value;

                byte[] statusCode = ASCIIEncoding.UTF8.GetBytes(csReport.StatusCode);// editRow.Cells["StatusCode"].Value.ToString());
                FillStatusCodes(statusCode);
            }
        }

        public void EditReportGridData(DataGridViewRow editRow, bool newReport)
        {
            ClearReportData();
            editExisting = true;
            StationTextBox.Text = editRow.Cells["Station"].Value.ToString();
            StreetNumberTextBox.Text = editRow.Cells["StreetNumber"].Value.ToString();
            StreetDirComboBox.Text = editRow.Cells["StreetDirection"].Value.ToString();
            StreetNameTextBox.Text = editRow.Cells["StreetName"].Value.ToString();
            CityTextBox.Text = editRow.Cells["CityCode"].Value.ToString();
            StateComboBox.Text = editRow.Cells["StateCode"].Value.ToString();
            CrossRoad1TextBox.Text = editRow.Cells["CrossRoad1"].Value.ToString();
            CrossRoad2TextBox.Text = editRow.Cells["CrossRoad2"].Value.ToString();
            LatDegTextBox.Text = AprsCalc.LatLonToDouble(editRow.Cells["Latitude"].Value.ToString()).ToString();
            LonDegTextBox.Text = AprsCalc.LatLonToDouble(editRow.Cells["Longitude"].Value.ToString()).ToString();
            DetailRichTextBox.Text = editRow.Cells["DetailText"].Value.ToString();

            if (!newReport)
            {
                ReportIdNumericUpDown.Value = Convert.ToInt32(editRow.Cells["ReportID"].Value);
                IncidentTimePicker.Value = (DateTime)editRow.Cells["IncidentTime"].Value;

                byte[] statusCode = ASCIIEncoding.UTF8.GetBytes(editRow.Cells["StatusCode"].Value.ToString());
                FillStatusCodes(statusCode);
            }
        }

        public void FillStatusCodes(byte[] statusCode)
        {
            if(statusCode[0] == 71)
                Green1.Checked = true;
            else if(statusCode[0] == 89)
                Yellow1.Checked = true;
            else if(statusCode[0] == 82)
                Red1.Checked = true;

            if(statusCode[1] == 71)
                Green2.Checked = true;
            else if(statusCode[1] == 89)
                Yellow2.Checked = true;
            else if(statusCode[1] == 82)
                Red2.Checked = true;

            if(statusCode[2] == 71)
                Green3.Checked = true;
            else if(statusCode[2] == 89)
                Yellow3.Checked = true;
            else if(statusCode[2] == 82)
                Red3.Checked = true;

            if(statusCode[3] == 71)
                Green4.Checked = true;
            else if(statusCode[3] == 89)
                Yellow4.Checked = true;
            else if(statusCode[3] == 82)
                Red4.Checked = true;

            if(statusCode[4] == 71)
                Green5.Checked = true;
            else if(statusCode[4] == 89)
                Yellow5.Checked = true;
            else if(statusCode[4] == 82)
                Red5.Checked = true;

            if(statusCode[5] == 71)
                Green6.Checked = true;
            else if(statusCode[5] == 89)
                Yellow6.Checked = true;
            else if(statusCode[5] == 82)
                Red6.Checked = true;

            if(statusCode[6] == 71)
                Green7.Checked = true;
            else if(statusCode[6] == 89)
                Yellow7.Checked = true;
            else if(statusCode[6] == 82)
                Red7.Checked = true;

            if(statusCode[7] == 71)
                Green8.Checked = true;
            else if(statusCode[7] == 89)
                Yellow8.Checked = true;
            else if(statusCode[7] == 82)
                Red8.Checked = true;

            if(statusCode[8] == 71)
                Green9.Checked = true;
            else if(statusCode[8] == 89)
                Yellow9.Checked = true;
            else if(statusCode[8] == 82)
                Red9.Checked = true;

            if(statusCode[9] == 71)
                Green10.Checked = true;
            else if(statusCode[9] == 89)
                Yellow10.Checked = true;
            else if(statusCode[9] == 82)
                Red10.Checked = true;

            if(statusCode[10] == 71)
                Green11.Checked = true;
            else if(statusCode[10] == 89)
                Yellow11.Checked = true;
            else if(statusCode[10] == 82)
                Red11.Checked = true;

            if(statusCode[11] == 71)
                Green12.Checked = true;
            else if(statusCode[11] == 89)
                Yellow12.Checked = true;
            else if(statusCode[11] == 82)
                Red12.Checked = true;

            if(statusCode[12] == 71)
                Green13.Checked = true;
            else if(statusCode[12] == 89)
                Yellow13.Checked = true;
            else if(statusCode[12] == 82)
                Red13.Checked = true;

            if(statusCode[13] == 71)
                Green14.Checked = true;
            else if(statusCode[13] == 89)
                Yellow14.Checked = true;
            else if(statusCode[13] == 82)
                Red14.Checked = true;

            if(statusCode[14] == 71)
                Green15.Checked = true;
            else if(statusCode[14] == 89)
                Yellow15.Checked = true;
            else if(statusCode[14] == 82)
                Red15.Checked = true;

            if(statusCode[15] == 71)
                Green16.Checked = true;
            else if(statusCode[15] == 89)
                Yellow16.Checked = true;
            else if(statusCode[15] == 82)
                Red16.Checked = true;
        }

        private void savePanelButton_Click(object sender, System.EventArgs e)
        {
            DateTime reportTime;
            string reportID;
            string statusCode;
            Coordinate lat = new Coordinate(LatDegTextBox.Text); //, LatMinTextBox.Text, LatSecTextBox.Text)
            Coordinate lon = new Coordinate(LonDegTextBox.Text); //, LonMinTextBox.Text, LonSecTextBox.Text)

            if (StationTextBox.Text.Trim().Length > 0)
            {
                reportTime = DateTime.Now;
                reportID = ReportIdNumericUpDown.Value.ToString().PadLeft(4,'0');
                statusCode = GetStatusCode();

                if(ReportToTextBox.Text.Trim().Length == 0)
                {
                    ReportToForm rtf = new ReportToForm();
                    if (rtf.ShowDialog() == DialogResult.OK)
                        ReportToTextBox.Text = rtf.ToCall;
                }
                if (ReportToTextBox.Text.Trim().Length > 0)
                {
                    // Create the report record.
                    messages.AddCSReport(configure[0].CallSign, ReportToTextBox.Text.Trim(), configure[0].DigiPath, StationTextBox.Text, reportID, IncidentTimePicker.Value, lat.ToAprsLatString(), lon.ToAprsLonString(), statusCode,
                                CityTextBox.Text, StateComboBox.Text.Substring(0, Math.Min(2, StateComboBox.Text.Length)), StreetNumberTextBox.Text, StreetDirComboBox.Text, StreetNameTextBox.Text,
                                CrossRoad1TextBox.Text, CrossRoad2TextBox.Text, DetailRichTextBox.Text);
                }
                else
                {
                    MessageBox.Show("The 'Report To/Destination' field may not be left blank.", "Incomplete Data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    ReportToTextBox.Focus();
                    return;
                }
                // Save the report data to disk.
                messages.WriteXml(configure[0].DataDir + @"\messages.xml");
                // Process the messages and reload reports in the main form.
                mainForm.ReloadReportDataToolStripMenuItem_Click(this, null);
                // Instantiate a new CSReportList object using the messages MessageList object.
                csReports = new CSReportList(messages);

                if (configure[0].InterfaceType != PacketControlType.Disabled)
                {
                    Radio radio = Radio.GetRadio();
                    if (radio.IsOpen)
                    {
                        radio.SendCSReport(ReportToTextBox.Text.Trim(), configure[0].DigiPath, StationTextBox.Text, reportID, IncidentTimePicker.Value, lat.ToAprsLatString(), lon.ToAprsLonString(), statusCode,
                            CityTextBox.Text, StateComboBox.Text.Substring(0, Math.Min(2, StateComboBox.Text.Length)), StreetNumberTextBox.Text, StreetDirComboBox.Text, StreetNameTextBox.Text,
                            CrossRoad1TextBox.Text, CrossRoad2TextBox.Text, DetailRichTextBox.Text);
                    }
                }
                // Clear existing station information.
                ClearReportData();
                // If auto update is turned on, save the KML file.
                //if (configure[0].SaveToKml)
                //{
                //    mainForm.WriteKml(Path.GetFullPath(configure[0].KmlFileLocation).TrimEnd('\\') + "\\" + configure[0].EventName.Trim() + "_features.kml");
                //    // Start a background process and, if an FTP server is configured, publish the file. 
                //    BackgroundWorker1.RunWorkerAsync();
                //}
            }
            else
                MessageBox.Show("The 'Station/Source' field may not be left blank.", "Incomplete Data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            // Set the focus back to the StationTextBox for the next report.
            StationTextBox.Focus();
        }

        private void NowButton_Click(object sender, EventArgs e)
        {
            IncidentTimePicker.Value = DateTime.Now;
        }

        private void Sub5Button_Click(object sender, EventArgs e)
        {
            IncidentTimePicker.Value = DateTime.Now.AddMinutes(-5);
        }

        private void Sub10Button_Click(object sender, EventArgs e)
        {
            IncidentTimePicker.Value = DateTime.Now.AddMinutes(-10);
        }

        private void LatDegTextBox_Leave(object sender, System.EventArgs e)
        {
            Coordinate lat = new Coordinate(LatDegTextBox.Text);

            if(Convert.ToDouble(lat.ToDegrees()) != 0)
            {
                if(lat.Degrees < 0)
                    lat.Degrees *= -1;
                LatDegTextBox.Text = lat.ToDecMinuteString();
            }
            else
            {
                if(LatDegTextBox.Text.Trim().Length > 0)
                    MessageBox.Show("Invalid coordinate format.\nValid formats are:\nTwo digit degrees\n-or-\nDecimal degrees\n-or-\nDegrees and decimal minutes\nExamples:\n32 or 32.1990833 or 32 11.945", "Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void LonDegTextBox_Leave(object sender, System.EventArgs e)
        {
            Coordinate lon = new Coordinate(LonDegTextBox.Text);

            if(Convert.ToDouble(lon.ToDegrees()) != 0)
            {
                if(lon.Degrees > 0)
                    lon.Degrees *= -1;
                LonDegTextBox.Text = lon.ToDecMinuteString();
            }
            else
            {
                if(LonDegTextBox.Text.Trim().Length > 0)
                    MessageBox.Show("Invalid coordinate format.\nValid formats are:\nThree digit degrees\n-or-\nDecimal degrees\n-or-\nDegrees and decimal minutes\nExamples:\n110 or 110.873220 or 110 52.393", "Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        //private string GetReportID(string station, string statusCode, DateTime reportTime)
        //{
        //    if (ReportIDTextBox.Text.Length > 0)
        //        return ReportIDTextBox.Text;
        //    else
        //    {
        //        return csReports.NextID;
        //    }
        //}

        private string GetStatusCode()
        {
            // 87 Is the ASCII value for the letter W which is the default value for each status code.
            byte[] statusCode = {87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87};

            if (Green1.Checked)
                statusCode[0] = 71; // 71 Is the ASCII value for the letter G
            else if (Yellow1.Checked)
                statusCode[0] = 89; // 89 Is the ASCII value for the letter Y
            else if (Red1.Checked)
                statusCode[0] = 82; // 82 Is the ASCII value for the letter R

            if(Green2.Checked)
                statusCode[1] = 71;
            else if(Yellow2.Checked)
                statusCode[1] = 89;
            else if(Red2.Checked)
                statusCode[1] = 82;

            if(Green3.Checked)
                statusCode[2] = 71;
            else if(Yellow3.Checked)
                statusCode[2] = 89;
            else if(Red3.Checked)
                statusCode[2] = 82;

            if(Green4.Checked)
                statusCode[3] = 71;
            else if(Yellow4.Checked)
                statusCode[3] = 89;
            else if(Red4.Checked)
                statusCode[3] = 82;

            if(Green5.Checked)
                statusCode[4] = 71;
            else if(Yellow5.Checked)
                statusCode[4] = 89;
            else if(Red5.Checked)
                statusCode[4] = 82;

            if(Green6.Checked)
                statusCode[5] = 71;
            else if(Yellow6.Checked)
                statusCode[5] = 89;
            else if(Red6.Checked)
                statusCode[5] = 82;

            if(Green7.Checked)
                statusCode[6] = 71;
            else if(Yellow7.Checked)
                statusCode[6] = 89;
            else if(Red7.Checked)
                statusCode[6] = 82;

            if(Green8.Checked)
                statusCode[7] = 71;
            else if(Yellow8.Checked)
                statusCode[7] = 89;
            else if(Red8.Checked)
                statusCode[7] = 82;

            if(Green9.Checked)
                statusCode[8] = 71;
            else if(Yellow9.Checked)
                statusCode[8] = 89;
            else if(Red9.Checked)
                statusCode[8] = 82;

            if(Green10.Checked)
                statusCode[9] = 71;
            else if(Yellow10.Checked)
                statusCode[9] = 89;
            else if(Red10.Checked)
                statusCode[9] = 82;

            if(Green11.Checked)
                statusCode[10] = 71;
            else if(Yellow11.Checked)
                statusCode[10] = 89;
            else if(Red11.Checked)
                statusCode[10] = 82;

            if(Green12.Checked)
                statusCode[11] = 71;
            else if(Yellow12.Checked)
                statusCode[11] = 89;
            else if(Red12.Checked)
                statusCode[11] = 82;

            if(Green13.Checked)
                statusCode[12] = 71;
            else if(Yellow13.Checked)
                statusCode[12] = 89;
            else if(Red13.Checked)
                statusCode[12] = 82;

            if(Green14.Checked)
                statusCode[13] = 71;
            else if(Yellow14.Checked)
                statusCode[13] = 89;
            else if(Red14.Checked)
                statusCode[13] = 82;

            if(Green15.Checked)
                statusCode[14] = 71;
            else if(Yellow15.Checked)
                statusCode[14] = 89;
            else if(Red15.Checked)
                statusCode[14] = 82;

            if(Green16.Checked)
                statusCode[15] = 71;
            else if(Yellow16.Checked)
                statusCode[15] = 89;
            else if(Red16.Checked)
                statusCode[15] = 82;

            return System.Text.ASCIIEncoding.UTF8.GetString(statusCode);
        }

        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        private void BackgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            if (configure[0].FtpKmlPublish & configure[0].FtpKmlHost.Trim().Length > 0 & configure[0].FtpKmlPath.Trim().Length > 0 & configure[0].FtpKmlLogin.Trim().Length > 0 & configure[0].FtpKmlPassword.Trim().Length > 0)
            {
                //FTP ftpKML;

                //ftpKML = new FTP(configDataSet.configuration[0].FtpKmlHost, configDataSet.configuration[0].FtpKmlPath, configDataSet.configuration[0].FtpKmlUser, configDataSet.configuration[0].FtpKmlPassword, configDataSet.configuration[0].FtpKmlPort);
                //BackgroundWorker1.ReportProgress(1);
                //// Attempt to log into the FTP Server.
                //if (ftpKML.Login())
                //{
                //    BackgroundWorker1.ReportProgress(2);
                //    // Set the FTP mode to binary
                //    ftpKML.SetBinaryMode(True);
                //    BackgroundWorker1.ReportProgress(3);
                //    // Upload the feature file.
                //    ftpKML.UploadFile(Path.GetFullPath(configDataSet.configuration[0].KmlFileLocation()).TrimEnd("\\") + "\\" + configDataSet.configuration[0].EventName.Trim() + "_features.kml");
                //    BackgroundWorker1.ReportProgress(4);
                //    ftpKML.CloseConnection();
                //    BackgroundWorker1.ReportProgress(5);
                //}
            }
        }

        private void BackgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
        {
            switch(e.ProgressPercentage)
            {
                case 1:
                    break;
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
                    break;
                default:
                    break;
            }
        }

        private void BackgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
        }
        #endregion
    }
}
